package cn.alpha.intell.rbtlib.share;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

/**
 * Created by zhangxiliang on 2016/12/1.
 */
public class GalleryContentResolver {
    public final String  KEY="shareUsers";

    private static  final String TAG="GalleryContentResolver";
    public static final String METHOD_LAST_IMAGE="getLastPhotoUrl";
    public static final String METHOD_INSERT_PHOTO="insertGalleryDb";
    public static final String BUNLDE_LAST_IMAGE="lastImageUrl";


    public Uri uri=Uri.parse("content://cn.alpha.intell.robot.gallery.GalleryContentProvider");

    public static GalleryContentResolver getInstance() {
        return InstanceHolder.instance;
    }



    public String getLastPhotoUrl(Context context){
        String lastUrl= null;
        try {
            Bundle bundle=context.getContentResolver().call(uri,METHOD_LAST_IMAGE,"",new Bundle());
            lastUrl = null;
            if(bundle!=null){
                lastUrl=bundle.getString(BUNLDE_LAST_IMAGE);
            }
        } catch (Exception e) {
            Log.e(TAG,Log.getStackTraceString(e));
        }
        return lastUrl;
    }


    public void insertGalleryDb(Context context,String imageUrl){

        try {
            context.getContentResolver().call(uri,METHOD_INSERT_PHOTO,imageUrl,null);
        } catch (Exception e) {
            Log.e(TAG,Log.getStackTraceString(e));
        }
    }

    static class InstanceHolder {
        final static GalleryContentResolver instance = new GalleryContentResolver();
    }


}
